<template>
  <div class="visitor-source">
    <!-- 数据概览 -->
    <div class="source-header">
      <div class="total-info">
        <span class="total-label">总访客数</span>
        <span class="total-value">{{ totalValue }}%</span>
      </div>
    </div>

    <!-- 来源地列表 -->
    <div class="source-list">
      <div 
        v-for="(item, index) in data" 
        :key="item.name"
        class="source-item"
        :style="{ animationDelay: index * 0.1 + 's' }"
      >
        <div class="source-info">
          <div class="source-icon">
            <svg viewBox="0 0 24 24">
              <path d="M12,11.5A2.5,2.5 0 0,1 9.5,9A2.5,2.5 0 0,1 12,6.5A2.5,2.5 0 0,1 14.5,9A2.5,2.5 0 0,1 12,11.5M12,2A7,7 0 0,0 5,9C5,14.25 12,22 12,22S19,14.25 19,9A7,7 0 0,0 12,2Z" fill="currentColor"/>
            </svg>
          </div>
          <div class="source-details">
            <div class="source-name">{{ item.name }}</div>
            <div class="source-value">{{ item.value }}%</div>
          </div>
        </div>
        
        <div class="source-progress">
          <div 
            class="progress-fill" 
            :style="{ 
              width: item.value + '%',
              backgroundColor: item.color,
              animationDelay: (index * 0.2 + 0.5) + 's'
            }"
          ></div>
        </div>
        
        <div class="source-rank">
          <span class="rank-number">{{ index + 1 }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, computed } from 'vue'

const props = defineProps({
  data: {
    type: Array,
    default: () => []
  }
})

// 计算总值（这里可以是100%或者真实访客数）
const totalValue = computed(() => {
  return props.data.reduce((sum, item) => sum + item.value, 0)
})
</script>

<style scoped>
.visitor-source {
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.source-header {
  background: rgba(0, 255, 136, 0.08);
  border: 1px solid rgba(0, 255, 136, 0.2);
  border-radius: 10px;
  padding: 0.8rem;
  text-align: center;
}

.total-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.total-label {
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.7);
}

.total-value {
  font-size: 1.1rem;
  font-weight: bold;
  color: #00ff88;
  text-shadow: 0 0 10px rgba(0, 255, 136, 0.5);
}

.source-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 255, 136, 0.3) transparent;
  padding: 2px 4px;
}

.source-list::-webkit-scrollbar {
  width: 3px;
}

.source-list::-webkit-scrollbar-track {
  background: transparent;
}

.source-list::-webkit-scrollbar-thumb {
  background: rgba(0, 255, 136, 0.3);
  border-radius: 2px;
}

.source-item {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.8rem;
  background: rgba(0, 255, 136, 0.04);
  border: 1px solid rgba(0, 255, 136, 0.15);
  border-radius: 10px;
  transition: all 0.3s ease;
  animation: slideInLeft 0.6s ease-out;
  position: relative;
}

.source-item:hover {
  background: rgba(0, 255, 136, 0.1);
  border-color: rgba(0, 255, 136, 0.3);
  transform: scale(1.02);
  box-shadow: 
    inset 0 0 10px rgba(0, 255, 136, 0.1),
    0 2px 8px rgba(0, 255, 136, 0.15);
}

.source-info {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex: 1;
}

.source-icon {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 255, 136, 0.1);
  border-radius: 6px;
  color: #00ff88;
  flex-shrink: 0;
}

.source-icon svg {
  width: 16px;
  height: 16px;
}

.source-details {
  flex: 1;
}

.source-name {
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.8);
  margin-bottom: 0.1rem;
}

.source-value {
  font-size: 1rem;
  font-weight: bold;
  color: #00ff88;
  text-shadow: 0 0 8px rgba(0, 255, 136, 0.5);
}

.source-progress {
  width: 60px;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  overflow: hidden;
  flex-shrink: 0;
}

.progress-fill {
  height: 100%;
  border-radius: 3px;
  transition: all 0.8s ease;
  position: relative;
  animation: progressExpand 1s ease-out;
}

.progress-fill::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
  animation: shimmer 2s infinite;
}

.source-rank {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 255, 136, 0.15);
  border-radius: 50%;
  flex-shrink: 0;
}

.rank-number {
  font-size: 0.8rem;
  font-weight: bold;
  color: #00ff88;
}

/* 排名前三的特殊样式 */
.source-item:nth-child(1) .source-rank {
  background: linear-gradient(135deg, #ffd700, #ffed4e);
}

.source-item:nth-child(1) .rank-number {
  color: #333;
}

.source-item:nth-child(2) .source-rank {
  background: linear-gradient(135deg, #c0c0c0, #e5e5e5);
}

.source-item:nth-child(2) .rank-number {
  color: #333;
}

.source-item:nth-child(3) .source-rank {
  background: linear-gradient(135deg, #cd7f32, #deb887);
}

.source-item:nth-child(3) .rank-number {
  color: #333;
}

/* 动画效果 */
@keyframes slideInLeft {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes progressExpand {
  from {
    width: 0 !important;
  }
}

@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* 响应式优化 */
@media screen and (max-width: 1400px) {
  .source-item {
    padding: 0.6rem;
    gap: 0.6rem;
  }
  
  .source-icon {
    width: 24px;
    height: 24px;
  }
  
  .source-icon svg {
    width: 14px;
    height: 14px;
  }
  
  .source-progress {
    width: 45px;
  }
  
  .source-rank {
    width: 20px;
    height: 20px;
  }
  
  .rank-number {
    font-size: 0.7rem;
  }
}
</style> 